<?php 
/* this file will update product stock value */
// load wordpress defaults, make global variables/functions available
$this_file = str_replace( '\\', '/', __FILE__ );
$this_file = explode( 'wp-content', $this_file );
$this_file = $this_file[ 0 ];
require( $this_file . 'wp-blog-header.php' ); 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>

<!-- head start -->

<head profile="http://gmpg.org/xfn/11">
	<?php
    $aOptions = SofaSuppaStore::initOptions( false );
	// handle font selection
	$google_fonts = $aOptions[ 'google_fonts' ];
	$font_str = $google_fonts;
	$font_str_arr = explode( ':', $font_str );
	$font_name = $font_str_arr[ 0 ];
	$clean_font_arr = explode( '+', $font_name );
	$clean_font_name = implode( ' ', $clean_font_arr );
    ?>
    <link href='http://fonts.googleapis.com/css?family=<?php echo $google_fonts; ?>' rel='stylesheet' type='text/css' />
    <link rel="stylesheet" href="<?php echo( get_template_directory_uri() . '/960.css' ); ?>" type="text/css" media="screen, projection" />
    <link rel="stylesheet" href="<?php echo( get_template_directory_uri() . '/screen.css' ); ?>" type="text/css" media="screen, projection" />
    <style type="text/css">
	/* handle basic styles according to google fonts selection */
	h1, h2, h3, h4, h5, h6 { font-family: '<?php echo $clean_font_name; ?>', Arial, sans-serif; font-weight: normal; }
	</style>
	<link rel="stylesheet" href="<?php bloginfo( 'stylesheet_url' ); ?>" type="text/css" media="screen, projection" />
    
    <?php wp_print_scripts( 'jquery' ); ?>
    <script src="<?php echo( get_template_directory_uri() . '/script/jquery.suppastore.custom.js' ); ?>" type="text/javascript"></script>
</head>

<!-- head end -->

<body>

<!-- main content start -->

<div id="lightcontent" class="container_8 clearfix">
    
	<?php
	// get item details
	if( $_SERVER[ 'REQUEST_METHOD' ] == 'GET' ) {
		$itemid    = !empty( $_GET[ 'itemid' ] ) ? intval( $_GET[ 'itemid' ] ) : NULL; // product id
		$itemsize  = !empty( $_GET[ 'itemsize' ] ) ? stripslashes( strip_tags( urldecode( $_GET[ 'itemsize' ] ) ) ) : NULL; // product size
		$itemstock = !empty( $_GET[ 'itemstock' ] ) ? intval( $_GET[ 'itemstock' ] ) : NULL; // in stock
		$inrow     = !empty( $_GET[ 'inrow' ] ) ? intval( $_GET[ 'inrow' ] ) : NULL; // in row
	} elseif( $_SERVER[ 'REQUEST_METHOD' ] == 'REQUEST' ) {
		$itemid    = !empty( $_REQUEST[ 'itemid' ] ) ? intval( $_REQUEST[ 'itemid' ] ) : NULL; // product id
		$itemsize  = !empty( $_REQUEST[ 'itemsize' ] ) ? stripslashes( strip_tags( urldecode( $_REQUEST[ 'itemsize' ] ) ) ) : NULL; // product size
		$itemstock = !empty( $_REQUEST[ 'itemstock' ] ) ? intval( $_REQUEST[ 'itemstock' ] ) : NULL; // in stock
		$inrow     = !empty( $_REQUEST[ 'inrow' ] ) ? intval( $_REQUEST[ 'inrow' ] ) : NULL; // in row
	}
	if( !$itemstock ) $itemstock = 0;
	if( !$inrow ) $inrow = 0;
	// get the post
	$post_obj = get_post( $itemid );
	// only Admin is allowed to edit stock inventory
	global $current_user;
	get_currentuserinfo();
    if( current_user_can( 'administrator' ) ) {
	?>

    <div id="featured" class="castshadow grid_8">
    
    	<!-- title start -->
    
        <h2 class="grid_8 alpha omega"><?php _e( "Update Stock Quantity", "sofa_suppastore" ); ?></h2>
        
        <!-- title end -->
        
        <!-- product image start -->
        
        <div id="prodimageset" class="grid_2 alpha">
        
        	<?php
			echo '<div class="grid_2 alpha omega">';
			$img_attr = array( 'class'	=> 'size-thumbnail alignleft topzero' );
			echo get_the_post_thumbnail( $post_obj->ID, 'thumbnail', $img_attr );
			echo '</div>';
			?>
        
        </div>
        
        <!-- product image end -->
        
        <!-- stock details start -->
        
        <div id="proddetails" class="grid_6 omega">
        
            <?php echo '<span class="spanpadded">' . __( "Product Name", "sofa_suppastore" ) . ': <strong>' . $post_obj->post_title . '</strong></span><span class="underline clearfix">&nbsp;</span><span class="spanpadded">' . __( "Product Size", "sofa_suppastore" ) . ': <strong>' . $itemsize . '</strong></span><span class="underline clearfix">&nbsp;</span><span class="spanpadded">' . __( "Currently in Stock", "sofa_suppastore" ) . ': <strong>' . $itemstock . '</strong></span><span class="underline clearfix">&nbsp;</span>'; ?>
            
            <form id="buyme" method="post" action="<?php echo get_template_directory_uri() . '/cart_handler.php'; ?>">
            
                <div class="grid_6 alpha omega">
                	<label for="stockqty"><?php _e( "Enter the new stock quantity:", "sofa_suppastore" ); ?>
                    <input type="text" name="itemstock" id="stockqty" value="<?php echo $itemstock; ?>" tabindex="771" />
                    </label>
                    <button type="submit" tabindex="772"><?php _e( "Update", "sofa_suppastore" ); ?></button>
                </div>
                
                <input type="hidden" name="itemid" id="itemid" value="<?php echo $post_obj->ID; ?>" />
                <input type="hidden" name="dothis" id="dothis" value="editstock" />
                <input type="hidden" name="inrow" id="inrow" value="<?php echo $inrow; ?>" />
                <?php wp_nonce_field( 'chck_ref_cc', 'sofa_suppastore_cc' ); ?>
            
            </form>
        
        </div>
        
        <!-- stock details end -->
        
    </div>
    
    <?php } else { ?>
    
    <!-- permission denied start -->
    
    <div id="featured" class="castshadow grid_8">
    
        <h2 class="grid_8 alpha omega"><font style="color: #ED1C24;"><?php _e( "Error!", "sofa_suppastore" ); ?></font></h2>
        
        <div class="grid_8 alpha omega">
        
        	<?php _e( "You don't have a permission to perform this action!", "sofa_suppastore" ); ?>
        
        </div>
        
    </div>
    
    <!-- permission denied end -->
    
    <?php } ?>
        
</div>

<!-- main content end -->

</body>
</html>